/**
 * 
 */
package com.a.plugin.reader;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.net.NetworkInfo.State;

import com.phonegap.api.Plugin;
import com.phonegap.api.PluginResult;
import com.phonegap.api.PluginResult.Status;

/**
 * @author Youssef el-Khouri
 *
 */
public class PluginReader extends Plugin {

    /* (non-Javadoc)
     * @see com.phonegap.api.Plugin#execute(java.lang.String, org.json.JSONArray, java.lang.String)
     */
    @Override
    public PluginResult execute(String action, JSONArray json, String callBackId) {
        JSONObject obj = new JSONObject();
        try {
            if(json == null)  {
                obj.put("value", "error!");
            } else {
                obj.put("value", json);
                this.sendJavascript("alert('hello world!');");
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        PluginResult plugin = new PluginResult(Status.OK, obj);
        return plugin;
    }
}
